package com.along.textdemo.manager;


import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.along.textdemo.R;
import com.along.textdemo.databinding.DialogVoiceDB;
import com.along.textdemo.utils.ScreenUtils;

public class DialogVoiceManager {

    private DialogVoiceDB dialogDB;

    private static final String TAG = "DialogManager";
    private Dialog mDialog;
    private Context mContext;

    public DialogVoiceManager(Context mContext) {
        this.mContext = mContext;
    }

    /**
     * 显示对话框
     */
    public void showRecordeingDialog() {
        mDialog = new Dialog(mContext, R.style.Theme_AudioDialog);
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
        dialogDB = DialogVoiceDB.bind(inflater.inflate(R.layout.dialog_voice, null));
        mDialog.setContentView(dialogDB.getRoot());
        Window window = mDialog.getWindow();
        //设置弹窗位置
        window.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
        int width = ScreenUtils.getScreenWidth(mContext);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = (int)(width);
        lp.y = 500;  //设置出现的高度，距离底部
        window.setAttributes(lp);

        mDialog.show();
    }

    float aTime = 0.0f;
    String path="";

    /**
     * 获取音频信息
     * @param time
     * @param filePath
     */
    public void getAudio(float time, String filePath){
        aTime = time;
        path = filePath;
    }

    /**
     * 开始波纹动画
     */
    public void showWave(){
        if (mDialog != null && mDialog.isShowing()) {
            dialogDB.dialogVoiceWave.startAnim();
        }
    }
    /**
     * 结束波纹动画
     */
    public void stopWave(){
        if (mDialog != null && mDialog.isShowing() && dialogDB.dialogVoiceWave.isPlaying()) {
            dialogDB.dialogVoiceWave.stopAnim();
        }
    }
    /**
     * 上滑展示，切换按钮
     */
    public void upShowRedCancel(){
        if (mDialog != null && mDialog.isShowing()) {
            dialogDB.dialogVoiceTvCancel.setVisibility(View.VISIBLE);
            dialogDB.dialogVoiceBtnCancel.setBackgroundResource(R.drawable.voice_cancel_red);
        }
    }
    /**
     * 上滑展示，切换按钮
     */
    public void downShowGreyCancel(){
        if (mDialog != null && mDialog.isShowing()) {
            dialogDB.dialogVoiceTvCancel.setVisibility(View.INVISIBLE);
            dialogDB.dialogVoiceBtnCancel.setBackgroundResource(R.drawable.voice_cancel_gray);
        }
    }

    /**
     * 发送按钮，对话框内容
     */
    public void sendToTitle(String audioPath){
        if (mDialog != null && mDialog.isShowing()) {
//           dialogDB.dialogText.setText("语音路径："+audioPath);
        }
    }

    /**
     * 录音时间过短提示
     */
    public void tooShort() {
        if (mDialog != null && mDialog.isShowing()) {

//            dialogDB.dialogText.setText(R.string.str_dialog_time_short);
        }
    }

    /**
     * 取消对话框
     */
    public void dismissDialog() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
            mDialog = null;
        }
    }

}

